from rest_framework import serializers

from order.models import OrderModel, DetailModel, MyGoodsModel


class OrderSerializer(serializers.ModelSerializer):
    class Meta:
        model = OrderModel
        fields = '__all__'


class DetailSerializer(serializers.ModelSerializer):
    class Meta:
        model = DetailModel
        fields = '__all__'


class MyGoodsSerializer(serializers.ModelSerializer):
    class Meta:
        model = MyGoodsModel
        fields = '__all__'


class MyGoodsSer(serializers.ModelSerializer):
    add_name = serializers.SerializerMethodField(read_only=True)
    add_address = serializers.SerializerMethodField(read_only=True)

    def get_add_name(self, obj):
        return obj.address.a_name

    def get_add_address(self, obj):
        return obj.address.address

    class Meta:
        model = MyGoodsModel
        fields = '__all__'
